home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
README
< prev
next >
Wrap
Text File
|
1994-08-01
|
48KB
|
1,711 lines
libgutil.a: Using the graphics utilities library
The following list represents the modules within libgutil.a
(following the list are documented notes for selected modules.
At the present time, those included have a `+' sign to the
left of their entry on the following list.)
abekas.c: support for digital video
acc.c: software accumulation buffer implementation
arg.c: arg_parse: command-line argument parser
bitmap.c: support for the allocation, manipulation, and display of bitmaps
bm.c: simple support for bitmap reading
brect.c: support for drawing beveled rectangles
brush.c: draw geometric brushes for impression
bufpool.c: support for allocation/freeing of a pool of buffers
charfill.c: creates and draws anti-aliased bitmaps of an outline font
checkchar.c: test a character outline for self intersections
cmap.c: color map support
+ cmyk.c: functions to support CMYK representations
+ colormod.c: define some transforms between different color models
corprt3.c: contains color correction support for generic corimg3 & sproof3
corprt4.c: color correction technique for multi angle screening w/4 colors
+ dispimg.c: general package for the display of images on all machines
dit.c: dither pixels into 1 bit deep bits
expr.c: expression evaluator - converts ascii string to floating point
fastimg.c: faster copies between long pixel data and image files
fastobj.c: support for spin format objects (obsoleted by sgiobj files)
fax.c: support for writing fax files
fft.c: simple 2-D fft support
file.c: miscellaneous support for files
filepath.c: pathname convenience package
fit2d.c: fit a plane to a 2D scalar function
follow.c: routines for manipulation of sgo format objects
fzoom.c: mag/mi -nify an array of longs using impulse zoom w/no filtering
gamma.c: gamma correction support for reading and writing c-map entries
gendit.c: general support for dithering; slow, but correct
geom.c: a software geometry package for computer graphics
getapixel.c: read a pixel value from a specific screen location
getfile.c: file manipulation support
getset.c: get and set values stored in ~/.gamma
gif.c: GIF img interface w/Lempel-Zim compression based on "compress"
+ glshade.c: simple support for describing materials and light sources
glshapes.c: basic euclidean shapes routines implemented in gl
+ glstuff.c: graphics library support functions
handline.c: human line code implementation
hideline.c: a hidden line algotithm
hipass.c: hi pass filter rows of an image using a 3x3 kernel
+ hist.c: support for histogram creation and display
homo2.c: homogeneous mapping in 2 dimensions
hypcurve.c: create hyperbolic and power curves for correcting printers
+ imgread.c: read an image into an array of longs
invgamma.c: invert arbitrary gamma look up tables
invmap.c: make and use inverse maps for dithering
izoom.c: magnify or minify a picture with or without filtering
lut.c: create and apply look up tables
manifesto.c: the manifesto of the futurist programmers
+ matrix.c: utilities for working with matrices
+ misc.c: miscellaneous system-based functions that do not rely on the gl
+ miscgl.c: miscellaneous functions that rely on the gl
movie.c: file support for movie files
mysystem.c: alternative implementation of system
objdraw.c: some utilities for drawing geometric objects
objfnt.c: support for spline and polygonal fonts
objlib.c: utilities for reading and writing geometric objects
objop.c: some operations on geometric objects
path.c: supports creation of PostScript stroked, filled, & beveled paths
+ percent.c: indicate percent done on time consuming operations
perlin.c: noise and dnoise routines
polyscan.c: polygon scanline rendering for characters
propdit.c: general propagation dither support
+ psimg.c: convert image data into b/w or color PostScript
pstri.c: postscript support for drawing lines, and shaded triangles
qquant.c: quick quant based on heckbert's median cut algoirthm
quant.c: quant - general median cut algorithm based on heckbert's m.c.a.
rand.c: generate high quality randow numbers (employs Berkeley random)
+ rct.c: management of rectangles
rctgl.c: more GL code for management of rectangles
rendchar.c: convert polygonal outlines into bitmaps
render.c: employing the GL to generate high resolution rendered images
resource.c: make it very very easy to use cursors, patterns, and bitmaps
rgn.c: managment of regions (an area described by a list of rectangles)
+ row.c: support for operations on image rows
rpc.c: put different things to a stream: floats,ints,strings & newlines
sample.c: support for managing sample sets
setscreen.c: PostScript style halftoning stuff
sgiobj.c: utilities for reading and writing sgiobj format geometry
sgiobjgl.c: GL support for drawing sgiobj format geometry
shade.c: support for describing materials and light sources by text files
shadow.c: make it easy to select a halftone gray pattern for shadows
simptex.c: stapuft comatible texture mapping support
sprender.c: generic gl rendering stuff
sptexture.c: stapuft comatible texture mapping support
stream.c: autotracing support: converts an image into lines
subpix.c: subpixel positioned trapazoid and line prims
textmap.c: use texture mapping to draw text
texture.c: support for software texture maps
tl.c: tri list file io support
tmeshobj.c: support to convert an sgi obj into triangle meshes
tomesh.c: convert independent triangles to large triangle meshes
+ track.c: simple track ball interface
+ turtle.c: a simple implementation of turtle graphics
type1rd.c: read an Adobe type 1 font into objfnt data structure
unmesh.c: convert tmesh calls into triangles
+ vcolor.c: provide virtual rgb and grey scale support
vcool.c: flag "bad" rgb pixel vals for encoded NTSC or PAL colour signal
+ vect.c: various functions to support operations on vectors
vidcomp.c: video compression support
=============================================================================
N O T E S O N M O D U L E S I N L I B G U T I L . A
=============================================================================
cmyk.c: functions to support CMYK representations
#include "math.h"
#include "stdio.h"
#include "image.h"
#include "lum.h"
rgb_to_cmyk(register int r, g, b; int *c, *m, *y, *k; short cortab[256])
Convert from rgb to cmyk color space. This implements grey component
replacement.
Inputs: r intensity 0 to 255
g intensity 0 to 255
b intensity 0 to 255
Outputs: c coverage 0 to 255
m coverage 0 to 255
y coverage 0 to 255
k coverage 0 to 255
An input value of rgb=[255,255,255] represents white. When this is
transformed to cmyk, we get cmyk=[0,0,0,0] which represents zero
coverage.
An input value of rgb=[128,128,128] represents 50 percent grey. When
this is transformed to cmyk, we get cmyk=[0,0,0,127] which represents
zero coverage by cmy, and 50 percent coverage by black.
frgb_to_cmyk(register float r, g, b; float *c, *m, *y, *k)
Convert from rgb to cmyk. This implements grey component replacement.
Inputs: r intensity 0 to 1.0
g intensity 0 to 1.0
b intensity 0 to 1.0
Outputs: c coverage 0 to 255
m coverage 0 to 255
y coverage 0 to 255
k coverage 0 to 255
An input value of rgb=[1.0,1.0,1.0] represents white. When this is
transformed to cmyk, we get cmyk=[0,0,0,0] which represents zero
coverage.
An input value of rgb=[0.5,0.5,0.5] represents 50 percent grey. When
this is transformed to cmyk, we get cmyk=[0,0,0,127] which represents
zero coverage by cmy, and 50 percent coverage by black.
=============================================================================
colormod.c: define some transforms between different color models.
#include "stdio.h"
#include <math.h>
#include "port.h"
Convert FROM various formats TO rgb:
irgb_to_rgb(int ir, ig, ib; float *r, *g, *b)
convert an integer rgb triplet into floating point. The integer
rgb values are in the range 0..255. The returned values are in
the range 0.0..1.0.
cmy_to_rgb(float c, m, y; float *r, *g, *b)
convert cyan, magenta, yellow floating point values to rgb floating point
values.
hls_to_rgb(float h, l, s; float *r, *g, *b)
convert hue, lightness, saturation floating point values to rgb floating
point values.
hsv_to_rgb(float h, s, v; float *r, *g, *b)
convert hue, saturation, value floating point values to rgb floating
point values.
hsb_to_rgb(float h, s, b; float *r, *g, *b)
convert hue, saturation, brightness floating point values to rgb floating
point values.
yiq_to_rgb(float y, i, q; float *r, *g, *b)
convert NTSC YIQ floating point values to rgb floating
point values.
rgb_to_rgb(float fr, fg, fb, *tr, *tg, *tb)
copy from rgb floating point values to rgb floating point values.
Convert TO various formats FROM rgb:
rgb_to_cmy(float r, g, b; float *c, *m, *y)
convert from rgb floating point values to cyan, magenta, yellow floating
point values.
rgb_to_irgb(float r, g, b; float *ir, *ig, *ib)
convert from normalized rgb floating point values to rgb integer values
in the range 0...255.
rgb_to_hls(float r, g, b; float *h, *l, *s)
convert from rgb floating point values to hue, lightness, saturation
floating point values.
rgb_to_hsv(float r, g, b; float *lh, *ls, *lv)
convert from rgb floating point values to hue, saturation, value floating
point values.
rgb_to_hsb(float r, g, b; float *lh, *ls, *lb)
convert from rgb floating point values to hue, saturation, brightness
floating point values.
rgb_to_yiq(float r, g, b; float *y, *i, *q)
convert from rgb floating point values to NTSC YIQ values.
rgbcomplement(float r, g, b, *cr, *cg, *cb)
this complements the color specified by r, g, and b and
returns this rgb color in cr,cg,cb. The complement color
will have the same saturation and value as the input
color, but the hue is rotated 180 degrees.
The following four functions allow you to select a preferred color system
using a call like setcolorsys(COLORSYS_HSV). After this is done,
fromrgb(float r,g,b,*s1,*s2,*s3) converts to that color space and
torgb(float s1,s2,s3,*r,*g,*b) converts from that color space to rgb.
setcolorsys(int sys)
setcolorsys defines what the current color system being used by the
TO/FROM format converter. Currently there are five possibilities:
COLORSYS_RGB rgb to rgb (and back)
COLORSYS_CMY cmy to rgb "
COLORSYS_HSV hsv to rgb "
COLORSYS_HLS hls to rgb "
COLORSYS_YIQ yiq to rgb "
getcolorsys(int sys)
returns the current color system being employed by the TO/FROM converters.
torgb(float r, g, b; float *tr, *tg, *tb)
converts from the current color space to rgb space.
fromrgb(float r, g, b; float *tr, *tg, *tb)
converts from rgb space to the current color space.
=============================================================================
dispimg.c: General package for the display of images on all machines.
#include "gl.h"
#include "get.h"
#include "dispimg.h"
#include "image.h"
#include "gfxmach.h"
This package deals with the problems of dithering RGB images onto the
screens of all IRISes from the very low end to the high end. This
is NOT what you need if you want to display iris images on a machine
with RGBmode(). Take a look at imgread.c and study longimagedata as
a way of doing the manipulation of IRIS 24-bit RGB images into
dithered 8-bit colormap images.
imagetype(IMAGE *image)
return one of three kinds of possible images:
RGBIMG: RGB (24-bit deep) image
SCREENIMG: a colormap (<= 12-bits deep) image
BWIMG: 1 channel (8-bits of grayscale) image
drawimage(DISPIMAGE *di; int xorg, yorg)
does the actual drawing of the image to the GL window. The correct
displaymode/machine type has already been determined and is used here
for proper pixel writing. xorg and yorg are viewport relative.
DISPIMAGE *makedisprgn(IMAGE *image; unsigned int x1, x2, y1, y2;
int show, xorg, yorg)
make the display region that can later be used by drawimage.
*image the image we wish to display.
x1, x2, y1, y2 the region inside the image itself that we wish
to display (image coordinate space).
show flag indicates whether to show the image as we
are making this display region (TRUE) or not (FALSE).
xorg, yorg specifies where to display the area of the image
indicated by (x1,x2,y1,y2) above relative to the
current viewport of our present GL window.
=============================================================================
glshade.c: Simple support for describing materials and light sources.
#include "stdio.h"
#include "gl.h"
This makes it easy for people without PHD's in GL to actually shade surfaces.
Here is the structure of a typical program:
main()
{
winopen("shade");
RGBmode();
doublebuffer();
gconfig();
winopen("blat");
matrixinit(); you must use two matrix model
.
.
perspective( . . . . );
shadeinit(); init shading after perspective
.
.
while(1)
cpack(0x00404060); clear the screen
clear();
zclear();
.
.
shadeon(); turn lighting on
setdiffuse(1.0,0.0,0.0); make the diffuse color red
drawobjwithnormals(); draw the object
shadeoff(); turn lighting off
.
.
swapbuffers(); swap buffers
}
}
matrixinit()
initialize the lighting matrix by entering MVIEWING mode and explicitly
loading the identity matrix on the lighting matrix stack.
shadeinit()
initialize the lighting matrix by entering MVIEWING mode and explicitly
loading the identity matrix on the lighting matrix stack.
shadeinit()
initialize a set of default materials and lights, and bind lighting to
MODEL 0
shadeon()
bind lighting to MODEL 1.
shadeoff()
bind lighting to MODEL 0.
setdiffuse(float r, g, b)
set the lighting model color to diffuse with the rgb floating point
triplet passed in.
setspecular(float r, g, b)
set the lighting model color to specular with the rgb floating point
triplet passed in.
setshininess(float s)
set the lighting model shininess value to s and then define Material
1 with that shininess value.
=============================================================================
glstuff.c: graphics library support functions.
#include "stdio.h"
#include "math.h"
#include "gl.h"
#include "device.h"
#include "port.h"
#include "gfxmach.h"
savewindow(char *name)
save the current gl window's contents into an image file
savewindow creates an image from the contents of the
current GL window. The name of the image is specified by
name.
printwindow()
save the current gl window's contents and send it to the printer.
This program executes a shell script called "printimage" to actually
print the image file. printimage should be placed in /usr/sbin
or somewhere in the default path. This small shell script
should look something like:
lp -dseiko < $1
if you have a seiko printer installed.
gfxmachine()
determine which kind of IRIS 4D machine this is. This function
returns one of the values defined in the include file "gfxmach.h".
The possible return values are:
constant numeric value meaning
----------------------------------------------------------------------
MACH3D 0 2000 and 3000 machines
MACH4D 1 Mips processor with first gen graphics
MACH4DGT 2 Mips processor with high perf graphics
MACH4DPI 3 Personal IRIS
MACH4D8 4 Mips machine with 8 bitplanes
MACH4DVGX 5 VGX machine
NOTE: MACH3D is being phased out of libgutil but is not completely
removed at this time.
smartsetdepth()
call lsetdepth with the maximum values for the current graphics
hardware. This call the function fsetdepth(float near, far)
described below with the arguments 0.0 and 1.0. This controls
the way that geometry z values map into hardware Z values for
zbuffering and depth cueing.
fsetdepth(float near; float far)
device independent way of setting lsetdepth. The values near and
far should be in the range 0.0 to 1.0. 0.0 will map into the
smallest legal lsetdepth value, while 1.0 will map into
the largest. This function actually uses zviewport below
to call lsetdepth.
zviewport(long near; long far)
this simply calls lsetdepth with the given values, and save
local copies, so that getzviewport may be used by an application
to read the current lsetdepth values.
getzviewport(long *lnear; long *lfar)
returns the current lsetdepth values from the last call to
zviewport.
drawmeshimage(unsigned long *imgdata; int xsize; int ysize)
draws an image as a triangle mesh. This is useful for creating
background images on machines that may not support texture mapping.
The pointer imgdata points to an array of longs that is xsize pixels
wide and ysize pixels high. The image will cover the same area as
a rectangle drawn with rectf(0.0,0.0,1.0,1.0).
/*
* meshimg.c:
*
* using longimagedata() (see imgread.c) to convert image file
* data into lrectwrite format, we then implement drawmeshimage()
* to demonstrate drawing an image as a triangle mesh.
* NOTE: this program works optimally with small images.
*
* Paul Haeberli and dave rat - 1991
*/
#include <stdio.h>
#include <gl/gl.h>
#include <gl/device.h>
int xsize, ysize;
long *imgdat;
main(argc,argv)
int argc;
char **argv;
{
short val;
if(argc<2) {
fprintf(stderr,"usage: meshimg: inimage.rgb\n");
exit(1);
}
winopen("meshimg");
RGBmode();
gconfig();
sizeofimage(argv[1],&xsize,&ysize);
printf("the size of the image is %d by %d\n",xsize,ysize);
imgdat = (long *)longimagedata(argv[1]);
drawit();
while(1) {
switch(qread(&val)) {
case REDRAW:
drawit();
break;
}
}
}
drawit()
{
reshapeviewport();
ortho2(0.0,1.0,0.0,1.0);
drawmeshimage(imgdat,xsize,ysize);
}
=============================================================================
hist.c: Support for histogram creation and display.
#include "hist.h"
#include "gl.h"
histogram *newhist(int min, max, nbuckets)
allocate a new histogram structure, assign the appropriate elements
passed in, and initialize to zero the nbuckets bucket list.
freehist(histogram *hist)
de-allocate the memory of structure hist.
clearhist(histogram *hist)
re-initialize all the buckets of the hist structure to zero.
addtohist(histogram *hist; unsigned short sptr; int n)
adds an array of integer values to the histogram. This is how
information is accumulated in a histogram.
showhist(histogram *hist)
draws the histogram into the current viewport.
=============================================================================
imgread.c: Read an image into an array of longs.
#include "stdio.h"
#include "image.h"
sizeofimage(char *name, int *xsize, int *ysize)
opens an image file and returns in xsize and ysize the width
and height of the image in pixels.
long *longimagedata(char *name)
convert image file data into lrectwrite format.
longimagedata opens the named image file, and returns a pointer to
an array of longs containing the pixel values of that image. This
function can read black and white, rgb and rgba images. These images
contain 1, 3, or 4 channels respectively. longimagedata is useful
for converting image file pixel data into a format that can
be used with lrectwrite(3G) and drawmeshimage described above.
(see the meshimg.c example prog (above) as well as the rectimg example
(below) for implementations of this tremendously useful function.)
short *shortimagedata(char *name)
convert color index image file data into rectwrite format.
shortimagedata opens the named image file, and returns a pointer to
an array of shorts containing the pixel values of that image. This
function can read an image file that contains color index pixels.
shortimagedata is useful for converting color index pixel image file
data into a format that can be used with rectwrite(3G).
char *charimagedata(char *name)
convert image pixel data into character data.
charimagedata opens the named image file, and returns a pointer to
an array of chars containing the pixel values of that image. This
function can read black and white image files onto an array of chars.
You'll have to figure out what this is good for.
/*
* rectimg -
* Display a color or black and white image on the IRIS making
* use of the extra*heem*ly swank longimagedata() function. Simple
* version for demo use. This will only work on machines that support
* RGB mode.
* Paul Haeberli - 1988
*
*/
#include "gl.h"
#include "device.h"
#include "image.h"
unsigned long *longimagedata();
IMAGE *image;
int xsize, ysize, zsize;
unsigned long *lptr;
int xscreensize;
int yscreensize;
main(argc,argv)
int argc;
char **argv;
{
short val;
if( argc<2 ) {
printf("usage: rectimg inimage\n");
exit(1);
}
xscreensize = getgdesc(GD_XPMAX);
yscreensize = getgdesc(GD_YPMAX);
sizeofimage(argv[1],&xsize,&ysize);
printf("size is %d %d\n",xsize,ysize);
if( xsize > xscreensize || ysize > yscreensize) {
printf("rectimg: input image is too big %d %d",xsize,ysize);
exit(1);
}
prefsize(xsize,ysize);
winopen("rectimg");
RGBmode();
gconfig();
lptr = (unsigned long *)longimagedata(argv[1]);
drawit();
while(1) {
switch(qread(&val)) {
case REDRAW:
drawit();
break;
}
}
}
drawit()
{
reshapeviewport();
lrectwrite(0,0,xsize-1,ysize-1,lptr);
}
=============================================================================
matrix.c: utilities for working with matrices.
#include "stdio.h"
identmat(float *matrix)
initialize the 4x4 matrix passed in by its address to the identity matrix.
xformpnt(float *matrix; float x, y, z; float *tx, *ty, *tz)
transform the point (x,y,z) by matrix, and return the transformed point
in tx, ty and tz.
copymat(float *mat1; float *mat2)
copy the 4x4 mat1 matrix values into mat2.
printmat(float mat[4][4])
print out the 4x4 matrix mat.
transpose(float from[4][4]; float to[4][4])
transpose the values in the 4x4 from matrix into the to matrix.
invertmat(float from[4][4]; float to[4][4])
invert the values in the 4x4 from matrix into the to matrix.
matrixmult(float a[4][4], b[4][4], c[4][4])
multiply the 4x4 matrices a and b, and save the result into matrix c.
=============================================================================
misc.c: Miscellaneous system-based functions that don't not rely on the gl.
#include "stdio.h"
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
strtolower(char *str)
convert the string, str, to lowercase. if there are no uppercase
characters str will be unchanged. if for any character within the
string, there is no corresponding lowercase character, that character
will remain unchanged.
ctos(unsigned char *cptr; unsigned short *sptr, int n)
convert a character string into its integer equivalent.
convert the contents of the character string cprt into the equivalent
short integer representation and store the result in sptr. ctos takes
one byte at a time from cptr, and assigns each bit into the same bit
location in sprt.
stoc(unsigned short *sptr, unsigned char *cptr, int n)
convert an integer into its character string equivalent.
convert the contents of the short integer sptr into the equivalent
character string representation and store the result in cptr. stoc
takes one byte at a time from sptr, and assigns each bit into the same
bit location in cptr.
delay(float secs)
delay will suspend the current process for secs*CLK_TCK clock ticks. if
secs is less than zero, nothing happens. the length of a clock tick,
CLK_TCK, is defined in the <limits.h> include file.
float uptime()
uptime returns the floating point value of the elapsed real time, in
clock ticks per second, from system startup time.
cleartime()
reset the current "beginning time" marker for a begin/end time
measurement.
float gettime()
gettime returns the elapsed time, represented as a floating point value,
from the last time gettime was called. call cleartime() to reset the
beginning moment of "elapsed time".
timefunc(int (*f)(); int n)
get elapsed time for function f being called n times.
timefunc takes the function pointed to by f and invokes it n times. it
then divides the elapsed time taken to loop n times by n and prints the
number of seconds taken per call to stderr.
tpercentfile(FILE *f)
specify an output file for tpercentdone to print its dots to.
tpercentdone(float p)
a textual percent done visual cue routine.
print out a row of dots real-time showing the percent of the current
job that is completed. tpercentdone prints out "......"
=============================================================================
miscgl.c: Miscellaneous functions that rely on the gl.
#include "values.h"
#include "math.h"
#include "stdio.h"
#include "gl.h"
#include "device.h"
drawfunc(int (*f)())
draw the function in an infinite loop waiting upon REDRAW events.
drawfunc takes the function pointed to by f, explicitly calls it once,
and then goes into an infinite loop where it blocks waiting for REDRAW
events which then cause it to reinvoke the drawing function.
qmouse()
queue the MOUSEX, MOUSEY, LEFT, RIGHT and MIDDLE -MOUSE buttons.
getmousex()
get the window-relative MOUSEX location.
getmousex returns the value of MOUSEX relative to the GL window's lower
left origin it is invoked within.
getmousey()
get the window-relative MOUSEY location.
getmousey returns the value of MOUSEY relative to the GL window's lower
left origin it is invoked within.
float fgetmousex()
get the normalized window-relative MOUSEX location.
fgetmousex returns the normalized floating point value of MOUSEX relative
to the GL window's lower left origin it is invoked within.
float fgetmousey()
get the normalized window-relative MOUSEY location.
fgetmousey returns the normalized floating point value of MOUSEY relative
to the GL window's lower left origin it is invoked within.
printsize()
print the x/y size of the current window.
print the integer values xsize and ysize of the current GL window to
stdout.
printorigin()
print the x/y screen origin of the current window.
print the absolute x/y screen coordinates of the origin of the current
GL window to stdout.
redraw(int (*f)())
test for REDRAW in the queue and if so, call the function pointed to by f.
test for a REDRAW token in the event queue, and, if present, call the
optionally supplied user function as well reshaping the viewport based
on the new size. if no user function is supplied, nothing happens
after the viewport is reshaped.
subviewport(long left, right, bottom, top)
create a viewport of size/location {left, right, bottom, top} within
the entire graphics console (XMAXSCREEN by YMAXSCREEN size).
subport(float left, right, bottom, top)
create a viewport based on screen normalized values.
subport creates a viewport based upon the passed in screen normalized
{left, right, bottom, top} values.
fillrect(float x1, y1, x2, y2)
this uses new polygon drawing routines to draw a filled rectangle.
This function will work with subpix(TRUE), etc.
drawrect(float x1, y1, x2, y2)
uses the new bgn/end -closedline routines to draw a the outline of
a rectangle.
fillrecti(int x1, y1, x2, y2)
this uses new polygon drawing routines to draw a filled rectangle.
This function will work with subpix(TRUE), etc.
drawrecti(int x1, y1, x2, y2)
uses the new bgn/end -closedline routines to draw a the outline of
a rectangle.
fillcirc(float x, y, rad)
uses the new bgn/end -polygon routines to draw a filled circle.
drawcirc(float x, y, rad)
uses the new bgn/end -closedline routines to draw a circle outline.
circsides(int n)
specify the number of line segments for the current circle.
=============================================================================
percent.c: Indicate percent done on time consuming operations.
#include "gl.h"
#include "device.h"
percentdone(float percent)
draw an hourglass cursor showing the percentage of work still to be done.
percentdone takes a floating point number in the range of 0.0..100.0
and draws an hourglass cursor representative of the percentage of
"time" left until the current task is complete.
dosystem(char *name)
bracket the system call to be executed by percentdone(0.0) and (100.0).
=============================================================================
psimg.c: Convert image data into b/w or color PostScript.
#include "image.h"
#include "math.h"
usebinaryps(int b)
specify input characters to be read as type string or as hexidecimal digits.
frametobwps(FILE *outf; IMAGE *image)
generate a frame of black and white PostScript output to outf from image.
frametorgbps(FILE *outf; IMAGE *image)
generate a frame of color PostScript output to outf from image.
tobwps(FILE *outf; int (*getfunc)(); short cortab[256];
int bitsper, xsize, ysize)
convert an image into black and white PostScript and store in outf.
torgbps(FILE *outf; int (*getfunc)(); short cortab[256];
int bitsper, xsize, ysize, nproc)
convert an image into rgb PostScript and store in outf.
tocmykps(FILE *outf; int (*getfunc)(); short cortab[256];
int bitsper, xsize, ysize, nproc)
convert an image into cmyk PostScript and store in outf.
=============================================================================
rct.c: Management of rectangles.
#include "rct.h"
#include "port.h"
rct *rctnew()
allocate memory for a new rct rectangle structure and return its pointer.
rctfree(rct *r)
de-allocate the memory pointed to by r.
rct *rctclone(rct *r)
allocate a new rectangle, copy rectangle r into it, and return its pointer.
rctcopy(rct *scr, *dst)
copy the contents of rectangle src into rectangle dst.
rctset(rct *r; int x1, y1, x2, y2)
assign the two x/y corners into rectangle r, and make sure the lessor and
greater of each are stored as the min and max values respectively.
rctsize(rct *r; int ox, oy, sizex, sizey)
assign the origin (ox,oy) and the origin plus the sizes to the two
rectangle corners and then make sure the lessor and greater of each
are stored as the min and max values respectively.
rctnormal(rct *r)
make sure the lessor and greater of each are stored as the min and max
values respectively.
rctoffset(rct *r; int dx, dy)
add dx and dy to both x and y parts respectively of rectangle r.
rctshrink(rct *r; int dx, dy)
add dx/dy to the x/y min corner and subtract dx/dy to the x/y max
corner value of rectangle r.
int rctinter(rct *src1, *src2, *dest)
find the min and max of x and y for the two rectangles src1 and src2.
if the max of each is greater than or equal to its min, assign these
four values to dest; if not, assign 0 to all four values of dest.
rctunion(rct *src1, *src2, *dest)
determine the min and max x and y values of rectangles src1 and src2
and assign these two the min and max x and y values of dest.
rctinside(rct *r; int x, y)
determine if x and y are both inside of rectangle r (or along its edge)
and return 1 if they are, else return 0.
rctequal(rct *r1, *r2)
determine if rectangles r1 and r2 are identical in position. if so,
return 1, else return 0.
rctempty(rct *r)
determine if either xmin equals xmax or ymin equals ymax. if so, return
1, else return 0.
rctdraw(rct *r)
draw the rectangle using the new bgn/end -closedline drawing routines.
rctfill(rct *r)
fills the rectangle using the new bgn/end -polygon drawing routines.
=============================================================================
row.c: Support for operations on image rows.
#include "image.h"
#include "lum.h"
zerorow(short *sptr; int n)
place n zero bytes in the string pointed to by sptr.
copyrow(short *s, *d; int n)
copies n bytes from string s to string d.
setrow(short *sptr; int val, n)
assign the n bytes in row sptr the value val. if n is zero assign
zero bytes to all locations in the string.
clamprow(short *iptr, *optr; int n)
clamp all values in the iptr row (of length n bytes) of less than zero
at zero and greater than 255 at 255 and store the clamped row in optr.
accrow(short *iptr, *sptr; int w, n)
add, subtract or multiply the values in iptr (of length n bytes) by
those in sptr (storing the results in iptr) depending on whether w is 1,
-1, or anything else respectively.
divrow(short *iptr, *optr; int tot, n)
divide every value in iptr (of length n bytes) by tot and store the
values in optr.
rgbrowtobw(unsigned short *rbuf, *gbuf, *bbuf, *obuf; int n)
convert the RGB pixel values (pointed to by rbuf, gbuf and bbuf of
length n bytes) into a single Black and White (8-bit) greyscale value
using the luminance values defined in ../include/lum.h.
addsrow(short *dptr, *sptr; int n)
add two short rows together of length n bytes and store their results
in dptr.
subsrow(short *dptr, *sptr; int n)
subtract the values in sptr from dptr (of length n bytes) and store
the results in dptr.
bitstorow(unsigned char *bits; short *sbuf; int n)
converts a row of binary one-bit data of length n bits into a row of
short pixel data of either 0 or 255 values.
rowtobits(short *sbuf; unsigned char *bits; int n)
thresholds the row of pixels (of length n bytes) against 128 and
converts this into a one-bit per pixel. If the pixel value is greater
than 128 it makes it one and if its less than 128 it makes it zero.
bitrevbytes(unsigned char *buf; int n)
bit reverse a stream of bytes of length n.
flipsrow(short *sptr; int n)
flip a row of shorts.
bwtocpack(unsigned short *b; unsigned long *l; int n)
convert a black and white row of length n bytes into cpack (long) format.
rgbtocpack(unsigned short *r, *g, *b; unsigned long *l; int n)
convert an rgb row of length n bytes into cpack (long) format.
rgbatocpack(unsigned short *r, *g, *b, *a; unsigned long *l; int n)
convert an rgba row of length n bytes into cpack (long) format.
cpacktorgb(unsigned long *l; unsigned short *r, *g, *b; int n)
convert a cpack row of length n bytes into an rgb row format.
cpacktorgba(unsigned long *l; unsigned short *r, *g, *b, *a; int n)
convert a cpack row of length n bytes into an rgba row format.
normrow(IMAGE *image; short *buf)
Normalize a row of image data.
getbwrow(IMAGE *image; char *buf; int y)
reads luminance information from either a B&W or RGB file.
putfliprow(IMAGE *image; short *buf; int y, z, flipcode)
putfliprow flips either the X direction or Y direction or both as rows
are being written out.
01 in the flipcode controls whether rows are mirrored in the X direction.
10 in the flipcode controls whether rows are mirrored in the Y direction.
getfliprow(IMAGE *image; short *buf; int y, z, flipcode)
getfliprow flips either the X direction or Y direction or both as rows
are being read in.
01 in the flipcode controls whether rows are mirrored in the X direction.
10 in the flipcode controls whether rows are mirrored in the Y direction.
=============================================================================
track.c: Simple track ball interface.
#include "gl.h"
#include "device.h"
#include "math.h"
#include "vect.h"
trackclick()
get and save the current MOUSEX and MOUSEY values.
trackpoll()
poll and update the state and position of the trackball.
tracktransform()
transform the trackball by premultiplying the current transformation
matrix by the trackball matrix.
trackball(float e[4], p1x, p1y, p2x, p2y)
simulate a trackball
Simulate a track-ball. Project the points onto the virtual trackball,
then figure out the axis of rotation, which is the cross product of
p1 p2 and O p1 (O is the center of the ball, 0,0,0)
Note: This is a deformed trackball--is a trackball in the center, but
is deformed into a hyperbolic solid of rotation away from the center.
It is assumed that the arguments to this routine are in the range
(-1.0 ... 1.0).
axis_to_quat(vect *a; float phi, e[4])
compute quaternion.
using the angle, a, and the axis, phi, compute its quaternion and store
the result in array e.
float tb_project_to_sphere(float r, x, y)
project onto a sphere or hyperbolic sheet.
Project an x, y pair onto a sphere of radius r OR a hyperbolic sheet if
we are away from the center of the sphere.
add_quats(float e1[4], e2[4], dest[4])
calculate a single rotation from two quaternion rotations.
Given two rotations, e1 and e2, expressed as quaternion rotations,
compute the equivalent single rotation and save the result into dest.
This routine also normalizes the result every RENORMCOUNT times it is
called, to keep error from accumulating.
normalize_quat(float e[4])
renormlize a quaternion.
Quaternions always obey: a^2 + b^2 + c^2 + d^2 = 1.0. If they don't
add up to 1.0, dividing by their magnitude will renormalize them.
Note: See the following for more information on quaternions:
- Shoemake, K., Animating rotation with quaternion curves, Computer
Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985.
- Pletinckx, D., Quaternion calculus as a basic tool in computer
graphics, The Visual Computer 5, 2-13, 1989.
build_rotmatrix(float m[4][4], e[4])
Build a rotation matrix, given a quaternion rotation.
vcopy3(float *a, *b)
copy the 3-element vector a into vector b.
myidentity()
load the identity matrix onto the top of the transformation matrix stack.
matinit()
specify MVIEWING mode, load the identity matrix on the stack, and set
lsetdepth to be the maximum legal values for the current graphics
hardware.
=============================================================================
turtle.c: A simple implementation of turtle graphics.
#include "values.h"
#include "math.h"
#include "gl.h"
CLEARSCREEN()
Erase the entire screen area.
MOVE(float distance)
Move some distance.
MOVETO(float x, y)
Move to a cartesian coordinate.
SPACETO(float x, y, z)
Move to a point in 3 space.
TURN(float angle)
Turn the turtle.
TURNTO(float angle)
Turn to a specific angle.
FILLCOLOR(int fillcolor)
Change the fillcolor to be the value of fillcolor.
FILLTEXTURE(int filltype)
Change the filltexture to be the value of filltexture.
PENCOLOR(int threadcolor)
Change the pencolor to be the value of threadcolor.
PENTYPE(int threadtype)
Change the pencolor to be the value of threadtype.
WHATCOLOR()
Return the current color.
WHEREAMI(float *x, *y, *h)
Return our current heading and position.
BEGINPOLY()
Start a polygon.
ENDPOLY()
Close and fill a polygon.
TEXT(float x, y; char *string)
Draw some text at position x,y.
VIEWPORT(float x1, y1, x2, y2)
Set the viewport.
WINDOW(float x1, y1, x2, y2)
Set the 2 dimensional orthographic window.
=============================================================================
vcolor.c: Provide virtual rgb and grey scale support.
#include "gl.h"
#include "get.h"
#define NOGREYPATTERNS
#include "colortbl.inc"
#include "vect.h"
a breakdown of the 2 colormodes we work with here:
REALRGB: this indicates the current displaymode we need to emulate
is either single or double buffered RGB.
MAPNEWS: indicates we're on a 4D IRIS machine where the current
display mode is colormap.
rgb(float fr, float fg, float fb)
take normalized rgb values, convert them to integers in the range 0..255
and then set this color value to be the current color.
rgbi(int r, int g, int b)
take an rgb triplet and set this to be the current color no matter what
the current display mode happens to be. then return either the color
lookup table index or the 24 bits of rgb information into an integer.
hsv(float h, float s, float v)
convert hue, saturation, value floating point values to normalized rgb
floating point values, set this color to be the current color, and
return this value either as a color lookup table index or as a 24 bits
worth of rgb information as an integer.
hsvi(int h, int s, int v)
convert hue, saturation, value integer values to normalized rgb floating
point values, set this color to be the current color, and return this
value either as a color lookup table index or as a 24 bits worth of rgb
information as an integer.
grey(fg)
takes a normalized floating point value representing a grey value and
defines this as the current color regardless of what the current
display mode is, and then returns this value either as a color lookup
table index or as a 24 bits worth of rgb information as an integer.
greyi(g)
takes an integer value in the range of 0..255 representing a grey value
and defines this as the current color regardless of what the current
display mode is, and then returns this value either as a color lookup
table index or as a 24 bits worth of rgb information as an integer.
pseudorgb()
define the current color mode to either be the kind of colormap used
with 8-bit systems which implements a swank dithering algorithm to
better simulate RGB resolution, in this case "MAPNEWS", or true RGBmode
is possible and the current color mode value is set to "REALRGB."
colorinit()
initialize the current colormode based on the current displaymode.
=============================================================================
vect.c: Various functions to support operations on vectors.
#include "vect.h"
vect *vnew()
allocate a new vector and return its pointer.
vect *vclone(vect *v)
allocate a new vector, copy vector v into it, and return its pointer.
vcopy(vect *v1, *v2)
copy the contents of v1 into v2.
vprint(vect *v)
print the x/y/z values of vector v to stdout.
vprint4(vect *v)
print the x/y/z/w values of vector v to stdout.
vset(vect *v; float x, y, z)
assign the vector (x, y, z) to v.
vzero(vect *v)
assign the four components (x, y, z, w) of vector v to be 0.0.
vone(vect *v)
assign the four components (x, y, z, w) of vector v to be 1.0.
vset4(vect *v; float x, y, z, w)
assign the values (x, y, z, y) to the vector v.
vnormal(vect *v)
normalize the vector v to be of unit length.
float vlength(vect *v)
compute and then return the length, or norm, of vector v.
vscale(vect *v; float mul)
scale the (x,y,z) components of vector by a factor of mul.
vmult(vect *src1, *src2, *dst)
multiply the individual components of vectors src1 and src2 and save
their results into dst.
vadd(vect *src1, *src2, *dst)
add the individual components of vectors src1 and src2 and save their
results into dst.
vsub(vect *src1, *src2, *dst)
subtract the individual components of vectors src1 and src2 and save
their results into dst.
vhalf(vect *v1, *v2, *half)
takes 2 vectors and gives back a vector halfway in between these 2.
float vdot(vect *v1, *v2)
compute and return the cosine of the angle, or dot product, between
vectors v1 and v2.
vcross(vect *v1, *v2, *cross)
using the cross product, compute the vector that is perpendicular to v1
and v2 and save it into cross.
vplane(vect *normal, *point, *plane)
generate the coefficients for the plane that is perpendicular to the
vector normal and passes through the vector point. save the resulting
coefficients in plane.
vdirection(vect *v1, *dir)
generate the normal vector of v1 and save it into dir.
makeplane(vect *p1, *p2, *p3, *v)
return a plane equation in the vector v for the 3 vertices p1, p2, & p3.
vreflect(vect *in, *mirror, *out)
create a vector in out that is the result of mirroring the in vector with
the mirror vector.
vmultmatrix(float m1[4][4], m2[4][4], prod[4][4])
multiply the row/column values of matrices m1 and m2 and save the
resulting matrix into prod.
vtransform(vect *v; float mat[4][4]; vect *vt)
transform vector v by matrix mat and save the result in vector vt.
vlerp(vect *v0, *v1, *v; float p)
using the parameter p, linearly interpolate the respective components of
vectors v0 and v1, and store the results in vector v.
float flerp(float f0, f1, p)
using the parameter p, linearly interpolate between 2 floating point
values f0 and f1. if p equals 0.0, f0 is returned. if p equals 1.0,
f1 is returned. if p equals 0.5, the average of f0 and f1 is returned.
lerp(int i0, i1; float p)
integer version of flerp--using the floating point parameter p, linearly
interpolate between the two integer values i0 and i1.
int trinormal(vect *p00, *p01, *p10, *n; float tol)
takes the 3 verticies, p00, p01, and p02, and returns the normal of that
triangle.